package com.jch.helloworld.configBeans.factoryBean;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestMain {

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("/beans/beans-factory.xml");
        System.out.println("通过静态工厂方法获取bean: ");
        BeanDemo sBean0 = (BeanDemo) ctx.getBean("staticFactory");
        System.out.println(sBean0);
        System.out.println("通过实例工厂方法获取bean: ");
        BeanDemo iBean1 = (BeanDemo) ctx.getBean("iFB");
        System.out.println(iBean1);
        System.out.println("使用FactoryBean接口实现获取bean: ");
        BeanDemo factoryBeanDemo0 = (BeanDemo) ctx.getBean("factoryBeanDemo");
        BeanDemo factoryBeanDemo1 = (BeanDemo) ctx.getBean("factoryBeanDemo");
        System.out.println("是否为单例：" + (factoryBeanDemo0 == factoryBeanDemo1));
        System.out.println(factoryBeanDemo0);
        System.out.println(factoryBeanDemo1);
    }

}
